const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象c.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sta:1,
    a:[],
    c:[],
    b:[],
    d:[],
    activeindex:100,
    bd:''
  },

  /* 页面跳转，支持tab和普通页面跳转 */
  link: function (e) {
    var url = Function.getDataSet(e, "surl");
    Function.linkTo(url);
  },


  onLoad: function (options) {
    this._getrcoe()
    this.jian();
  },
  

  _getrcoe(){
    let that = this;
    let data ={
      id:wx.getStorageSync('members')['id']
    };
    index.getrcoe(data,(res)=>{
      if(res.code == 200){
        that.setData({
          count: res.count
        })
        if(Array.isArray(res.data)){
          that.ragarr(res.data)
        }else{
          wx.redirectTo({
            url: '../desc4/desc4?tq=' + JSON.stringify(res.data) + "&count=" + that.data.count
          })
        }
       
      }
    })


  },

  jian(){
    let that = this;
    let data = {
      uid: wx.getStorageSync('members').id,
      phone: wx.getStorageSync('phoneNumber')
    }
    index.jian(data, (res) => {
      if (res.code == 200) {
        // Function.layer('你已领取' + res.data + "红包");
        that.setData({
          zfad: false
        })
      } else {
        // Function.layer(res.msg);
        if (res.msg == '请先绑定手机') {
          wx.showModal({
            title: '提示',
            content: '你还未绑定手机是否前往绑定',
            showCancel: false,
            success(res) {
              if (res.confirm) {
                wx.navigateTo({
                  url: '/pages/shouye/bindMobile/bindMobile'
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })

        }
      }
    })
  },
  ragarr(data){
 
    var a = data.filter((item, index) => { return item.type == 1 })
    var b = data.filter((item, index) => { return item.type == 2 })
    var c = data.filter((item, index) => { return item.type == 3 })
    var d = data.filter((item, index) => { return item.type == 4 })

    this.setData({
      a,b,c,d
    })
    
  },
  selit(e){
    this.setData({
      activeindex:parseInt(e.currentTarget.dataset.index),
      bd:e.currentTarget.dataset.id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  next(){
    var that = this;
    wx.navigateTo({
      url: '../desc1/desc1?bd=' + that.data.bd + "&arr=" + JSON.stringify(that.data.b) + "&arr1=" + JSON.stringify(that.data.c) + "&arr2=" + JSON.stringify(that.data.d) 
    })
  }

 
})